Cayenne User Documentation
Tutorial Object Relational Mapping

Lets go back to CayenneModeler where we have the newly created project open. Our goal is to map the following schema:

Mapping Database Tables

Start by adding the ARTIST table. Mapped database tables are called "DbEntities" in Cayenne. Click on "Create DbEntity" button (or use "Project > Create DbEntity" menu). In "DbEntity Name" field enter "ARTIST". Then click on "Create Attribute" button on the entity toolbar (second button on the right). This action changes the view to the "Attribute" tab and adds a new attribute (attribute means a "table column" in this case) called "untitledAttr". Let's rename it to ID, make it an INTEGER and make it a PK:

Similarly add NAME VARCHAR and DATE_OF_BIRTH DATE attributes.

Repeat this procedure for PAINTING and GALLERY entities.

Mapping Database Relationships

Now we need to specify relationships between ARTIST, PAINTING and GALLERY tables. Start by creating a one-to-many ARTIST/PAINTING relationship:

Mapping Java Classes

Now that the database schema mapping is complete, CayenneModeler can create mappings of Java classes (aka "ObjEntities") by deriving everything from DbEntities. At present there is no way to do it for the entire DataMap in one click, so we'll do it for each table individually.

Unless you want to customize the Java class and property names (which you can do easily) the mapping is complete.


Next Step: Tutorial Generate Database and Java Classes


.